How a room becomes a 3D corridor you walk through: the view from inside, drawn from the room's tiles by code, with walls, a flat floor and ceiling, walking and turning.
A top-down room is a grid of tiles. The 3D view draws the same grid as a place you stand in: every solid tile is a wall that rises in front of you, every other tile is open floor, and you look along it from a camera that you can walk and turn. It is how corridor shooters and dungeon crawlers are drawn, and it needs nothing in the Room Editor: you paint the room the way you always do, and a little code switches the view on.
It is GBML only and Advance only. On the other consoles the functions are grayed out, with the reason.
For each of 120 columns across the screen, the console sends a ray out from the camera, straight along the line of sight of that column. The ray steps from tile edge to tile edge until it hits a solid tile. How far it went tells how tall that wall looks: near walls are tall, far walls are short. Where along the wall the ray hit tells which slice of the wall picture to copy into that column. Above the wall the column is the ceiling color, below it the floor color. Do that for all 120 columns, each 2 pixels wide, and you have a picture of the whole view. That is the entire trick, and it is why this kind of 3D is fast enough for a small console: no solid shapes, only one short ray per column.
The picture is drawn into two screens that take turns, so you never see it half finished, once a frame.
view3d_start(ts_walls);
view3d_camera(100, 100, 0);
view3d_colors(#303848, #6A5038);if (action_held(up)) { view3d_move(1.5, 0); }
if (action_held(down)) { view3d_move(-1.5, 0); }
if (action_held(left)) { view3d_turn(3); }
if (action_held(right)) { view3d_turn(-3); }That is a complete game of walking around. view3d_move stops at walls and slides along them; see Collision in 3D.
The walls are only the stage. Enemies and items in 3D puts things in it (a picture standing on the floor that shrinks with distance and hides behind walls), asks whether one place can see another, finds what a shot hits, and slides doors open. For a game with a HUD, view3d_height stops the view above it.
| What | Value |
|---|---|
| Picture size | 120 columns, each 2 pixels wide, by 160 rows |
| Room size | up to 64 by 64 tiles |
| Wall pictures | 32 by 32 pixels, up to 64 |
| Colors | one set of 256 for the whole view: the wall pictures share what is left after the floor and ceiling |
| Positions | room pixels from the top-left corner; a tile is 8 |
| Angles | degrees, counter-clockwise: 0 looks right, 90 looks up the room |
| View width | 66 degrees, change it with view3d_width (30 to 120) |
| View height | the whole screen (160 rows); view3d_height makes it shorter and leaves the rows below black for a HUD |